import { GTileList } from "../../../../com/mui/controls/GTileList";
import { WareHouseExtendItem } from "./WareHouseExtendItem";
import { DragEvent } from "../../../../com/mui/events/DragEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Language } from "../../../../extend/language/Language";
import { DragDropData } from "../pack/DragDropData";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GameConst } from "../../../component/gconst/GameConst";
type int = number;
//class WareHouseItemExtendPanel
    
    export  class WareHouseItemExtendPanel extends GTileList
    {
        constructor()
        {
            super();
            this.initList();
            return;
        }

        /* internal  */initList(): void
        {
            this.setSize(246, 41);
            this.rowHeight = 36;
            this.columnCount = 5;
            this.columnWidth = 36;
            this.horizontalGap = 5;
            this.verticalGap = 5;
            this.setStyle("skin", new Object /* flash.display.Bitmap */());
            this.setStyle("cellRenderer", WareHouseExtendItem);
            this.addEventListener(DragEvent.Event_Move_In, this.moveInBagHandler);
            Dispatcher.addEventListener(WareHouseExtendItem.OpenWareHouseExtendItemRequest, this.requestOpenExtendHandler);
            return;
        }

        /* internal  */moveInBagHandler(arg1: DragEvent): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc7=null;
            if (this.dragable) 
            {
                loc1 = arg1.dragItem as BaseItem;
                loc2 = arg1.dropItem as BaseItem;
                loc3 = arg1.dragSouce as ItemData;
                loc4 = loc2.itemData;
                loc5 = loc3.itemInfo.item.category;
                loc6 = loc3.itemInfo.item.type;
                if (loc3 && loc5 == ECategory._ECategoryProp && loc6 == EProp._EPropPackage) 
                {
                    if (!loc2.data["isOpened"]) 
                    {
                        Alert.show(Language.getString(42516), null, Alert.OK | Alert.CANCEL, null);
                        return;
                    }
                    loc7 = new DragDropData(loc3.posType, loc2.posType, loc3.uid, loc1.posIndex, loc2.posIndex, loc3, loc4);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WareHouse_DragInExtendItem, loc7));
                }
            }
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */requestOpenExtendHandler(arg1: DataEvent): void
        {
            Alert.show(Language.getStringByParam(42517, this.getNeedIngot().toString()), null, Alert.OK | Alert.CANCEL, null, this.closeHandle);
            return;
        }

        /* internal  */getNeedIngot(): number
        {
            var loc3=null;
            var loc1=0;
            var loc2=0;
            while (loc2 < dataProvider.length) 
            {
                loc3 = dataProvider.getItemAt(loc2);
                if (loc3.hasOwnProperty("isOpened")) 
                {
                    if (loc3["isOpened"]) 
                    {
                        ++loc1;
                    }
                }
                ++loc2;
            }
            var loc4=loc1;
            switch (loc4) 
            {
                case 2:
                {
                    return GameConst.AddExtendBarCapacityFirstConst;
                }
                case 3:
                {
                    return GameConst.AddExtendBarCapacitySecondConst;
                }
                case 4:
                {
                    return GameConst.AddExtendBarCapacityThirdConst;
                }
                case 5:
                {
                    return GameConst.AddExtendBarCapacityFourthConst;
                }
            }
            return 0;
        }

        /* internal  */closeHandle(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.OpenWareHouseExtendItem));
            }
            return;
        }

        public /* var */dragable: Boolean=true;
    }
